//
//  CropPicsViewController.m
//  ShrimpCrowdordering
//
//  Created by jimmy on 2018/9/12.
//  Copyright © 2018年 郑洲. All rights reserved.
//

#import "CropPicsViewController.h"
#import "OriginalPublishVC.h"
#import "TKImageView.h"

@interface CropPicsViewController ()<UIGestureRecognizerDelegate>

@property (nonatomic, strong) TKImageView  * tkImageView;

@end

@implementation CropPicsViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    [self setTitle:@"裁剪图片"];
    
    
    [self createdTkImageView];
}

- (void)createdTkImageView
{
    CGFloat height = (SCREEN_WIDTH - ScreenX375(30)) / _fixImage.size.width * _fixImage.size.height;
    _tkImageView = [[TKImageView alloc] initWithFrame:CGRectMake(ScreenX375(15), ScreenX375(15), SCREEN_WIDTH - ScreenX375(30), height)];
    _tkImageView.layer.masksToBounds = YES;
    _tkImageView.layer.cornerRadius = 10.0;
    _tkImageView.contentMode = UIViewContentModeScaleAspectFill;
    [self.view addSubview:_tkImageView];
    //需要进行裁剪的图片对象
    _tkImageView.toCropImage = _fixImage;
    //是否显示中间线
    _tkImageView.showMidLines = YES;
    //是否需要支持缩放裁剪
    _tkImageView.needScaleCrop = YES;
    //是否显示九宫格交叉线
    _tkImageView.showCrossLines = YES;
    _tkImageView.cornerBorderInImage = NO;
    _tkImageView.cropAreaCornerWidth = 44;
    _tkImageView.cropAreaCornerHeight = 44;
    _tkImageView.minSpace = 30;
    _tkImageView.cropAreaCornerLineColor = [UIColor whiteColor];
    _tkImageView.cropAreaBorderLineColor = [UIColor whiteColor];
    _tkImageView.cropAreaCornerLineWidth = 2.5;
    _tkImageView.cropAreaBorderLineWidth = 1;
    _tkImageView.cropAreaMidLineWidth = 0;
    _tkImageView.cropAreaMidLineHeight = 1;
    _tkImageView.cropAreaMidLineColor = [UIColor whiteColor];
    _tkImageView.cropAreaCrossLineColor = [UIColor whiteColor];
    _tkImageView.cropAreaCrossLineWidth = 0.5;
    _tkImageView.initialScaleFactor = .8f;
    _tkImageView.cropAspectRatio = 1.0;
    _tkImageView.maskColor = [UIColor clearColor];
    
    UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(0, SCREEN_HEIGHT - ScreenX375(49) - NAVIGATION_BAR_HEIGHT, SCREEN_WIDTH, ScreenX375(49))];
    [button setTitle:@"确定" forState:UIControlStateNormal];
    [button setTitleColor:REXADECIMALCOLOR(@"#ffffff") forState:UIControlStateNormal];
    button.titleLabel.font = Kfont(18);
    [button setBackgroundImage:ImageWithName(@"按钮背景") forState:UIControlStateNormal];
    [button addTarget:self action:@selector(sureCrop) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:button];
}

- (void)sureCrop
{
    [self.navigationController popViewControllerAnimated:true];
    _tkImageView.toCropImage = [_tkImageView currentCroppedImage];
    if (_transportFixPicsBlock) {
        _transportFixPicsBlock(_tkImageView.toCropImage);
    }
}



@end
